package com.workstudy.wstudy.service.impl;

import java.util.LinkedList;
import java.util.List;

import com.workstudy.common.core.domain.entity.SysUser;
import com.workstudy.common.utils.DateUtils;
import com.workstudy.wstudy.domain.Constants;
import com.workstudy.wstudy.domain.WstApply;
import com.workstudy.wstudy.domain.WstPostUser;
import com.workstudy.wstudy.mapper.WstPostUserMapper;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.workstudy.wstudy.mapper.WstPostMapper;
import com.workstudy.wstudy.domain.WstPost;
import com.workstudy.wstudy.service.IWstPostService;
import com.workstudy.common.core.text.Convert;

import javax.security.auth.Subject;

/**
 * 岗位管理Service业务层处理
 * 
 * @author sun
 * @date 2021-04-04
 */
@Service
public class WstPostServiceImpl implements IWstPostService 
{
    @Autowired
    private WstPostMapper wstPostMapper;

    @Autowired
    private WstPostUserMapper wstPostUserMapper;

    /**
     * 查询岗位管理
     * 
     * @param postId 岗位管理ID
     * @return 岗位管理
     */
    @Override
    public WstPost selectWstPostById(Long postId)
    {
        return wstPostMapper.selectWstPostById(postId);
    }

    /**
     * 查询岗位管理列表
     * 
     * @param wstPost 岗位管理
     * @return 岗位管理
     */
    @Override
    public List<WstPost> selectWstPostList(WstPost wstPost)
    {
        return wstPostMapper.selectWstPostList(wstPost);
    }

    /**
     * 新增岗位管理
     * 
     * @param wstPost 岗位管理
     * @return 结果
     */
    @Override
    public int insertWstPost(WstPost wstPost)
    {
        SysUser user = (SysUser) SecurityUtils.getSubject().getPrincipal();
        wstPost.setCreateUserId(user.getUserId());
        wstPost.setCreateBy(user.getUserName());
        wstPost.setPostStatus(Constants.PostStatus.WAIT_FOR_PUBLISH.toString());
        wstPost.setStatus(Constants.ApprovalStatus.WAITING_FOR_APPROVAL.toString());
        wstPost.setCreateTime(DateUtils.getNowDate());
        return wstPostMapper.insertWstPost(wstPost);
    }

    @Override
    public int insertWstPostFinished(WstPost wstPost) {
        return wstPostMapper.insertWstPostFinished(wstPost);
    }

    /**
     * 修改岗位管理
     * 
     * @param wstPost 岗位管理
     * @return 结果
     */
    @Override
    public int updateWstPost(WstPost wstPost)
    {
        wstPost.setUpdateTime(DateUtils.getNowDate());
        return wstPostMapper.updateWstPost(wstPost);
    }

    /**
     * 删除岗位管理对象
     * 
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteWstPostByIds(String ids)
    {
        return wstPostMapper.deleteWstPostByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除岗位管理信息
     * 
     * @param postId 岗位管理ID
     * @return 结果
     */
    @Override
    public int deleteWstPostById(Long postId)
    {
        return wstPostMapper.deleteWstPostById(postId);
    }
}
